02. Organizing API endpoints
Organizing API endpoints
Organizing API Endpoints
FSND C2 L3 A02 Organizing API Endpoints
When organizing API endpoints, they should be based on the resources instead of on actions. The request methods will determine what action should be taken at a given URL endpoint. Your entire API's scheme should be consistent, clear and concise. Below are the principles and examples from the video, for your reference:
Principles
- Should be intuitive
-
Organize by resource
- Use nouns in the path, not verbs
- The method used will determine the operation taken
- GOOD:
- BAD:
-
Keep a consistent scheme
- Plural nouns for collections
- Use parameters to specify a specific item
- GOOD:
- BAD:
-
Don’t make them too complex or lengthy
-
No longer than
collection/item/collection
- GOOD:
- BAD:
-
No longer than
Methods & Endpoints Review
The request method used will determine the operation performed for the given resource URI. Though your API documentation should explain exactly what operation is performed and data returned via the response, it should be intuitive for anyone using your API, such as in the example below.
FSND C2 L3 A03 Methods And Endpoints Review
Organizing API endpoints Quiz
SOLUTION:
genres/1/moviesOrganizing API endpoints Quiz 2
SOLUTION:
POST genres/1/moviesQUIZ QUESTION: :
The following API endpoints are poorly formatted. Match each endpoint with the principle of API endpoints that it violates.
ANSWER CHOICES:
Endpoint |
Principle |
---|---|
Use nouns in the path, not verbs |
|
Use parameters to specify a specific item |
|
Plural nouns for collections |
|
Endpoints should not be lengthy or complex |
SOLUTION:
Endpoint |
Principle |
---|---|
Use nouns in the path, not verbs |
|
Use parameters to specify a specific item |
|
Plural nouns for collections |
|
Endpoints should not be lengthy or complex |